{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3af38bae-3e6b-4003-b36a-1367f7230953",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from mayavi.mlab import *\n",
    "\n",
    "def test_triangular_mesh():\n",
    "    \"\"\"An example of a cone, ie a non-regular mesh defined by its\n",
    "        triangles.\n",
    "    \"\"\"\n",
    "    n = 8\n",
    "    t = np.linspace(-np.pi, np.pi, n)\n",
    "    z = np.exp(1j * t)\n",
    "    x = z.real.copy()\n",
    "    y = z.imag.copy()\n",
    "    z = np.zeros_like(x)\n",
    "\n",
    "    triangles = [(0, i, i + 1) for i in range(1, n)]\n",
    "    x = np.r_[0, x]\n",
    "    y = np.r_[0, y]\n",
    "    z = np.r_[1, z]\n",
    "    t = np.r_[0, t]\n",
    "\n",
    "return triangular_mesh(x, y, z, triangles, scalars=t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "41970673-2477-440b-97f8-ad75af421655",
   "metadata": {},
   "outputs": [],
   "source": [
    "test_triangular_mesh()\n",
    "show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "debacb8c-57b9-48aa-8cdf-b4b1c9fd02f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create the data.\n",
    "from numpy import pi, sin, cos, mgrid\n",
    "dphi, dtheta = pi/250.0, pi/250.0\n",
    "[phi,theta] = mgrid[0:pi+dphi*1.5:dphi,0:2*pi+dtheta*1.5:dtheta]\n",
    "m0 = 4; m1 = 3; m2 = 2; m3 = 3; m4 = 6; m5 = 2; m6 = 6; m7 = 4;\n",
    "r = sin(m0*phi)**m1 + cos(m2*phi)**m3 + sin(m4*theta)**m5 + cos(m6*theta)**m7\n",
    "x = r*sin(phi)*cos(theta)\n",
    "y = r*cos(phi)\n",
    "z = r*sin(phi)*sin(theta)\n",
    "\n",
    "# View it.\n",
    "from mayavi import mlab\n",
    "s = mlab.mesh(x, y, z)\n",
    "mlab.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "EFEM",
   "language": "python",
   "name": "efem"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
